package org.java.jdk8Stream;

import lombok.extern.slf4j.Slf4j;

/**
 * @Description Lambda Demo
 * @Date 2024/10/8 10:29
 * @Created by 10574
 */

@Slf4j
public class LambdaDemo {
    public static void main(String[] args) {
        //1. new方式调用
        final OrderService orderService1 = new OrderServiceImpl();
        orderService1.add();
        //2. 匿名内部类调用
        final OrderService orderService2 = new OrderService() {
            @Override
            public void add() {
                System.out.println("-------orderService2-------");
            }
        };
        orderService2.add();
        //3. lambda调用
        final OrderService orderService3 = () -> {
            System.out.println("-------orderService3-------");
        };
        orderService3.add();

        final NumberService numberService = (a, b) -> {
            return a - b;
        };
        final int result = numberService.execute(1, 2);
        log.info("-------result:{}-------", result);

    }

    @FunctionalInterface
    public interface OrderService {
        void add();
    }

    @FunctionalInterface
    public interface NumberService {
        int execute(int a, int b);
    }

    @Slf4j
    public static class OrderServiceImpl implements OrderService {

        @Override
        public void add() {
            log.info("-------orderService1-------");
        }
    }
}
